<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>上传文件</title>
        <style>
            *{
              margin: 0;
              padding: 0;
            }
            .head-btn{
                text-align: center;
                margin-top: 200px;
            }
            .file {
                position: relative;
                display: inline-block;
                background: #1678ff;
                border: 1px solid #1678ff;
                border-radius: 10px;
                padding: 10px 25px;
                overflow: hidden;
                color: #ffffff;
                text-decoration: none;
                text-indent: 0;
                font-size: 14px;
            }
            .file input {
                position: absolute;
                font-size: 200px;
                right: 0;
                top: 0;
                opacity: 0;
            }
            .file:hover {
                background: #1678ff;
                border-color: #1678ff;
                color: #ffffff;
                text-decoration: none;
            }
            .determine{
                color: #FFFFFF;
                background-color: #007AFF;
                display: inline-block;
                font-size: 20px;
                border-radius: 5px;
                padding: 8px 24px;
            }
            .showFileName{
                display: inline-block;
                height: 30px;
                min-width: 300px;
            }
            .btn {
                display: block;
                margin: 20px auto;
                padding: 5px;
                background-color: #007aff;
                border: 0;
                color: #ffffff;
                height: 40px;
                width: 200px;
                border-radius: 5px;
                cursor: pointer;
            }
            .btn1 {
                display: block;
                margin: 20px auto;
                padding: 5px;
                background-color: #007aff;
                border: 0;
                color: #ffffff;
                height: 40px;
                width: 200px;
                border-radius: 5px;
                cursor: pointer;
            }
            .btn-red {
                background-color: #dd524d;
            }
            .btn-yellow {
                background-color: #f0ad4e;
            }
            .desc {
                padding: 10px;
                color: #999999;
            }
    </style>
    </head>
    <body>
        <div class="head-btn">
            <form action="" method="post">
                <a href="javascript:;" class="file">检测商业计划书
                    <input type="file" id="uploadFile">
                </a>
            </form>
        </div>
        <!-- <div>
            <button class="btn" type="button" data-action="redirectTo">确定</button>
            <button class="btn1" type="button" data-action="navigateBack">取消</button>
        </div> -->

        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
        <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>

        <script>

            // function getQuery(name) { // 获取uni传值
            //     // 正则：[找寻'&' + 'url参数名字' = '值' + '&']（'&'可以不存在）
            //     let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            //     let r = window.location.search.substr(1).match(reg);
            //     if(r != null) {
            //         // 对参数值进行解码
            //         return unescape(r[2]);
            //     }
            //     return null;
            // }
            // console.log(uni.getStorageSync("Mtoken")); // 调用获取参数

            $(".file").on("change", "input[type='file']", function() {
                // let filePath = $(this).val();
                // localStorage.setItem("fileAddress", filePath);
                // let lastname = localStorage.getItem("fileAddress");
                // console.log(99999999999999999,lastname)

                var fileItem  = document.getElementById('uploadFile').files[0];
                // console.log(ipt.files[0]);
                // let params = ipt.files[0]
                var formdata = new FormData();
                formdata.append('file', fileItem);

                console.log(formdata);
                // uni.showLoading({
                //     title: '分析中',
                // })
                $.ajax({
                  url: 'https://bootapi.51bmj.cn/bmj-api/api/cms/businessPlanEvaluation/evaluationBusinessPlan',
                  type: "POST",
                  processData: false,
                  contentType: false,
                  data:formdata,
                  headers: {
                    'X-Access-Token': localStorage.getItem("Mtoken")
                  },
                  success: function(data) {
                    console.log(9999999999,data)
                    // alert(data.message)
                    // uni.redirectTo({
                    //   url: '/pages/user/personal/personal',
                    // });
                    if (data.code === 200) {            
                        // setTimeout(()=>{
                            // uni.hideLoading()
                            uni.navigateTo({
                                url: `/pages/business/detail/Index?id=${data.result}`,
                            })
                        // },5000)
                    } else {
                        // uni.showToast({
                        //     title: res.message,
                        //     icon: "none"
                        // });
                        // uni.hideLoading();
                    }
                  },
                  error: function(err) {
                    alert('上传失败')
                  }
                });
                // var formdata = new FormData(); // 创建一个form类型的数据
                // formdata.append("headimgurl",ipt.files[0]); // 获取上传文件的数据
                // formdata.append("operate","UpLoadFile"); // 获取上传文件的数据
                // formdata.append("name","name"); // 获取上传文件的数据


                // formData.append('file', file, file.name)
                // let params = formData.get('file')
                // console.log(11111111111111,formdata)
                // if (lastname != "") {
                //     $(".showFileName").html(lastname);
                // } else {
                //     $(".showFileName").html("");
                // }
            });

            $('.btn').click(function(evt) {
              var ipt = document.getElementById('uploadFile');
              console.log(ipt.files[0]);
              var formdata = new FormData(); // 创建一个form类型的数据
              formdata.append("headimgurl",ipt.files[0]); // 获取上传文件的数据
              formdata.append("operate","UpLoadFile"); // 获取上传文件的数据
              formdata.append("name","name"); // 获取上传文件的数据
              console.log(formdata)
              // $.ajax({
              //   url: '后端接口',
              //   type: "POST",
              //   processData: false,
              //   contentType: false,
              //   data:formdata,
              //   headers: {
              //     'token': getQuery('token')
              //   },
              //   success: function(data) {
              //     alert(data.message)
              //     uni.redirectTo({
              //       url: '/pages/user/personal/personal',
              //     });
              //   },
              //   error: function(err) {
              //     alert('上传失败')
              //   }
              // });
            });

        </script>
    </body>
</html>